package admin

import (
	"github.com/kataras/iris/v12"
	"iris_blog/utils"
)

type Tag struct {
}

func (t Tag) GetTagList(i iris.Context) {

	result := []map[string]interface{}{}
	utils.DB.Raw("SELECT * FROM tag").Find(&result)

	i.JSON(map[string]interface{}{
		"code": 20000,
		"data": result,
	})
}

func (t Tag) AddTag(i iris.Context) {
	result := map[string]interface{}{}
	i.ReadJSON(&result)

	results := map[string]interface{}{}
	utils.DB.Raw("INSERT INTO tag ( title) VALUES (?)",result["value"]).Find(&results)

	i.JSON(map[string]interface{}{
		"code":20000,
		"data":"添加成功",
	})
}

func (t Tag) DelTag(i iris.Context) {
	result := map[string]interface{}{}
	i.ReadJSON(&result)

	results := []map[string]interface{}{}
	utils.DB.Raw("DELETE FROM tag WHERE id= ?",result["id"]).Find(&results)

	i.JSON(map[string]interface{}{
		"code": 20000,
		"data": result,
	})
}
